<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>HuYa协议登录管理</title>
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <!-- 标签页图标 -->
    <link rel="shortcut icon" href="/images/icon/menu_title_1.jpg" type="image/x-icon" />
</head>
<script src="/js/layui/layui.all.js" charset="utf-8"></script>
<script src="/js/jquery.js" charset="utf-8"></script>
<body>
<ul class="layui-nav" lay-filter="">
    <li class="layui-nav-item"><a href="/menu">登录</a></li>
    <li class="layui-nav-item layui-this">
        <a href="javascript:;">关于本站</a>
        <dl class="layui-nav-child"> <!-- 二级菜单 -->
            <dd><a href="#">qq:1084986263</a></dd>
            <dd><a href="#">手机:18110225799</a></dd>
            <dd><a href="#">需要账号请看上方</a></dd>
        </dl>
    </li>
    <li class="layui-nav-item">
        <a href="javascript:;">管理员选项</a>
        <dl class="layui-nav-child"> <!-- 二级菜单 -->
            <dd><a href="#" onclick="collectorCookies()">采集所有用户cookie</a> </dd>
            <dd><a href="#" onclick="saveCollectorCookies()">保存采集用户的cookies</a> </dd>
            <dd><a href="#">敬请等待...</a></dd>
        </dl>
    </li>
</ul>



<span style="color: red;" id="collectorCookiesMessage"></span>
    <div class="layui-form-item layui-form">
        <label class="layui-form-label">YY号</label>
        <div class="layui-input-block">
            <input type="text" id="yyid" value="1784302750" name="title" required lay-verify="required"
                   placeholder="请输入YY号" autocomplete="off" class="layui-input">
            <button class="layui-btn" onclick="allCookieLogin()">所有用户cookie登录</button>
        </div>
    </div>


<table class="layui-table">
    <colgroup>
        <col width="150">
        <col width="200">
        <col>
    </colgroup>
    <thead>
    <tr>
        <th>序号</th>
        <th>姓名</th>
        <th>账号</th>
        <th>密码</th>
        <th>状态</th>
        <th>弹幕消息<button class="layui-btn layui-btn-normal" onclick="sendMessage()">一键发送弹幕</button></th>
    </tr>
    </thead>
    <tbody id="tbody">

    <tr th:each="userDto,iterStat : ${userList}">
        <td th:text="${iterStat.index+1}"></td>
        <td th:text="${userDto.name}"></td>
        <td th:text="${userDto.account}"></td>
        <td th:text="${userDto.password}"></td>
        <td>不在线</td>
        <td><input type="text" id="message" value="666666" name="title" required
                   placeholder="请输入弹幕消息" autocomplete="off" class="layui-input"></td>
    </tr>
    </tbody>
</table>
<!--
<div id="page" class="layui-main layui-box"></div>
-->


</body>

<script>
    //注意：导航 依赖 element 模块，否则无法进行功能性操作
    layui.use('element', function(){
        var element = layui.element;
        element.init();
        //…
    });

    function sendMessage() {
        if (localStorage.login != -1) {
            layer.msg("请登录并获得权限..!");
            return;
        }
    }

    function allCookieLogin() {
        if (localStorage.login != -1) {
            layer.msg("请登录并获得权限..!");
            return;
        } else {
            console.log("2222");
            $.ajax({
                url: "/user/allCookieLogin",
                type: "GET",
                data: {
                    yyid: $("#yyid").val()
                },
                success: function (data) {
                    layer.msg(data);
                },
                error: function (e) {
                    console.log(e)
                }

            });
        }
    }

    function collectorCookies() {
        //if (localStorage.login != -1) {
        if (false) {
            layer.msg("请登录并获得权限..!");
            return;
        } else {
            $.ajax({
                url: "/user/collectorCookies",
                type: "GET",
                data: {},
                success: function (data) {
                    $("#collectorCookiesMessage").text(data);
                },
                error: function (e) {
                    console.log(e)
                }

            });
        }
    }

    function saveCollectorCookies() {
        if (localStorage.login != -1) {
            layer.msg("请登录并获得权限..!");
            return;
        } else {
            $.ajax({
                url: "/user/saveCollectorCookies",
                type: "GET",
                data: {},
                success: function (data) {
                    layer.msg(data);
                },
                error: function (e) {
                    console.log(e)
                }

            });
        }
    }

    function page() {
        getPageCount();
        localStorage.limit = 5;
        layui.use('laypage', function () {
            var laypage = layui.laypage;

            //执行一个laypage实例
            laypage.render({
                elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
                , count: localStorage.count //数据总数，从服务端得到
                , limit: localStorage.limit
                , layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
                , prev: "<"
                , next: ">"
                , groups: 3
                , limits: [10, 20, 50]
                , jump: function (obj, first) { //触发分页后的回调
                    if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                        $("#tbody").html('');//先清空原先内容
                    }
                    localStorage.limit = obj.limit;
                    //pageBindPatientList( obj.curr, obj.limit);
                }
            });
        });

    }

    function getPageCount() {

        $.ajax({
            url: "/user/count",
            type: "GET",
            async: false,
            data: {},
            success: function (data) {
                localStorage.count = data;
                console.log("count--->>>>>>>>>>" + data);
            },
            error: function (e) {
                console.log(e)
            }

        });
    }

    $(function () {
        //page();
    })
</script>
</html>